package com.rainfull.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;

public class RUIAPConnDlg extends Activity implements OnClickListener 
{
	private Intent m_inIntent = null;
	private String m_strSSID = "";
	private int  nLevel = 0;
	private String m_strPwd = "";
	private int test = 0;
	@Override
    public void onCreate(Bundle savedInstanceState) 
	{
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		super.onCreate(savedInstanceState);        
		setContentView(R.layout.ap_conn_dlg);             
        m_inIntent = getIntent();        
        m_strPwd = m_inIntent.getStringExtra("pwd");
        m_strSSID = m_inIntent.getStringExtra("ssid");
        int nLoginState = m_inIntent.getIntExtra("login", 1);
        nLevel = m_inIntent.getIntExtra("level", -1);
        
        ImageView imgApLevel =(ImageView)findViewById(R.id.an_conn_img_level);
        imgApLevel.setImageResource(nLevel);
        
        TextView texSSID =(TextView)findViewById(R.id.tex_ap_con_ssid);
        texSSID.setText(m_strSSID);
        
        EditText editApPwd =(EditText)findViewById(R.id.apPwd);
        editApPwd.setText(m_strPwd);
        
        Button bButtonOk = (Button) findViewById(R.id.btApConnOk);
        bButtonOk.setOnClickListener(this);
        Button bButtonCancle = (Button) findViewById(R.id.btApConnCancle);
        LinearLayout ll = (LinearLayout) findViewById(R.id.ap_conn_ll_1);
        /*if (nLoginState == 0)//没有登录不显示login对话框
        {
        	ll.removeView(findViewById(R.id.ap_conn_checkbox_share));
        	ll.removeView(findViewById(R.id.ap_conn_check_share));
        }*/
        bButtonCancle.setOnClickListener(this);
	}
    public void onClick(View v) 
    {    	
    	if (v.getId() == R.id.btApConnCancle)
    	{
    		finish();
    		return;
    	}
    	else if (v.getId() == R.id.btApConnOk)
    	{    		
    		final EditText editApPwd =(EditText)findViewById(R.id.apPwd);
    		m_inIntent.putExtra("share", 1);
    		CheckBox checkBox = null;
    		if (findViewById(R.id.ap_conn_checkbox_share) != null)
    		{
    			checkBox =(CheckBox)findViewById(R.id.ap_conn_checkbox_share);
	    		//是否共享网络
		    	if (checkBox.isChecked())
		    		m_inIntent.putExtra("share", 1);
		    	else
		    		m_inIntent.putExtra("share", 0);
    		}
	    	m_inIntent.putExtra("pwd", editApPwd.getText().toString());
	    	m_inIntent.putExtra("ssid", m_strSSID);
	    	m_inIntent.putExtra("index", test);
	    	setResult(RESULT_OK, m_inIntent);
	    	finish();
    	}
    }          
}
